#ifndef JOPERATE_H
#define JOPERATE_H

#include <QtCore/qglobal.h>

#ifndef J_MUTEX_LOCKER
# define J_MUTEX_LOCKER(mutexType, _mutex, ...) \
	std::unique_lock<mutexType> __mutex_locker__##__VA_ARGS__(_mutex); \
	Q_UNUSED(__mutex_locker__##__VA_ARGS__)
#endif

#ifndef J_STD_MUTEX_LOCKER
# define J_STD_MUTEX_LOCKER(_mutex, ...) \
	J_MUTEX_LOCKER(std::mutex, _mutex, __VA_ARGS__)
#endif

#ifndef J_QMUTEX_LOCKER
# define J_QMUTEX_LOCKER(_mutex, ...) \
	QMutexLocker __mutex_locker__##__VA_ARGS__(&_mutex); \
	Q_UNUSED(__mutex_locker__##__VA_ARGS__)
#endif

#ifndef J_MUTEX_LOCKER_RELOCK
# define J_MUTEX_LOCKER_RELOCK(...) \
	__mutex_locker__##__VA_ARGS__.lock()
#endif

#ifndef J_MUTEX_LOCKER_UNLOCK
# define J_MUTEX_LOCKER_UNLOCK(...) \
	__mutex_locker__##__VA_ARGS__.unlock()
#endif

/*------------------------------------------------------------------------------------------------*/

#define J_WRITE_LOCKER(_rwlock, ...) \
	QWriteLocker __write_locker__##__VA_ARGS__(&_rwlock); \
	Q_UNUSED(__write_locker__##__VA_ARGS__);

# define J_WRITE_LOCKER_UNLOCK(...) \
	__write_locker__##__VA_ARGS__.unlock()

# define J_WRITE_LOCKER_RELOCK(...) \
	__write_locker__##__VA_ARGS__.relock()

#define J_READ_LOCKER(_rwlock, ...) \
	QReadLocker __read_locker__##__VA_ARGS__(&_rwlock); \
	Q_UNUSED(__read_locker__##__VA_ARGS__);

# define J_READ_LOCKER_UNLOCK(...) \
	__read_locker__##__VA_ARGS__.unlock()

# define J_READ_LOCKER_RELOCK(...) \
	__read_locker__##__VA_ARGS__.relock()

/*------------------------------------------------------------------------------------------------*/

#if QT_VERSION < QT_VERSION_CHECK(5,7,0)
# define J_OVERLOAD(func, ...)  QOverload<__VA_ARGS__>::of(&func)
#endif //5.7.0


#endif //JOPERATE_H
